import { Card, Col, Row } from 'antd';
import React, { useEffect, useState } from "react";
import Mycard from './components/mycard/index'
import { apiParticipationCourse ,apiCourse} from "@/api/api";
const Courses = (props:any) => {
    const {url,id}=props;
    const [data,setData]=useState([])
    function fetchData() {
      if (typeof id !== "undefined") {
        apiCourse(url,id).then((res) => setData(res.data)).catch((error) => {
          console.error('apiCourse 请求失败:', error);
        });
      } else {
        apiParticipationCourse(url).then((res) => setData(res.data)) .catch((error) => {
          console.error('apiParticipationCourse 请求失败:', error);
        });
      }
    }
    useEffect(()=>{
        fetchData();
    },[url,id])
    return (
        <>
        <Row gutter={[16, 48]}>
          {data.map((item:any) => (
            <Col span={8} key={item.id}>
              <Mycard data={item} />
            </Col>
          ))}
        </Row>
      </>
    )
};

export default Courses;